package org.aurora.core.server.expression.cron;

import org.aurora.core.common.exception.ExpressionParseException;
import org.aurora.core.server.expression.AbstractExpression;
import org.aurora.core.server.expression.Expression;

import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;

public class CronExpression extends AbstractExpression implements Expression {
    private QuartzCronExpression quartzCronExpression;

    public CronExpression(String expression) throws ExpressionParseException {
        try {
            this.quartzCronExpression = new QuartzCronExpression(expression);
        } catch (ParseException e) {
            throw new ExpressionParseException();
        }
    }

    @Override
    public TimeZone getTimeZone() {
        return this.quartzCronExpression.getTimeZone();
    }

    @Override
    public void setTimeZone(TimeZone timeZone) {
        this.quartzCronExpression.setTimeZone(timeZone);
    }


    @Override
    public Date getNextValidTimeAfter(Date now) {
        return this.quartzCronExpression.getNextValidTimeAfter(now);
    }
}
